<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title>生成帐号</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <style type="text/css">
    	span.required {
    		color: red;
    		margin-right: 6px;
    	}
    </style>
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>生成帐号</h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">生成帐号</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success ">
            <form id="form" class="form-horizontal" action="${ctx}/sysUser/zxSaveUser.html" method="post">
            	<input type="hidden" name="id" value="${user.id}" />
            	<input type="hidden" name="opType" value="0" />
            	<input type="hidden" name="locked" value="0" />
            	<input type="hidden" name="type" value="${user.type}" />
            	
                <div class="box-body">
                    <div class="form-group form-group-xs">
                        <label for="username" class="col-sm-2 text-right"><span class="required">*</span>帐号：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="username" name="username" value="${user.username}" placeholder="帐号" type="text" readonly="readonly">
                        </div>
                        <label for="name" class="col-sm-2 text-right"><span class="required">*</span>用户名称：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="name" name="name" value="${user.name}" placeholder="用户名称" type="text" readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="roleId" class="col-sm-2 text-right"><span class="required">*</span>用户角色：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" id="roleId" name="role.id">
                            	<c:if test="${ roleList != null }">
                            		<c:forEach items="${ roleList }" var="role">
                            			<option value="${ role.id }" ${user.role.id == role.id ? "selected='true'" : ""}>${ role.name }</option>
                            		</c:forEach>
                            	</c:if>
                            </select>
                        </div>
                        <label for="email" class="col-sm-2 text-right"><span class="required">*</span>邮箱：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="email" name="email" value="${user.email}" placeholder="邮箱" type="text" readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="phone" class="col-sm-2 text-right"><span class="required">*</span>联系电话：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="phone" name="phone" value="${user.phone}" placeholder="联系电话" type="text" maxlength="20">
                        </div>
                        <label for="status" class="col-sm-2 text-right"><span class="required">*</span>用户状态：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" id="status" name="status">
                            	<option value="1" ${user.status == 1 ? "selected='true'" : ""}>启用</option>
                            	<option value="0" ${user.status == 0 ? "selected='true'" : ""}>停用</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="remark" class="col-sm-2 control-label">备注：</label>
                        <div class="col-sm-10">
                            <textarea class="form-control" id="remark" name="remark" rows="3" placeholder="备注" maxlength="500">${user.remark}</textarea>
                        </div>
                    </div>
                </div>
                <div class="box-footer text-center">
                    <button type="button" class="btn btn-success btn-sm" onclick="auditSaveUser();">保  存</button>
                    <a href="javascript:backToList();" class="btn btn-danger btn-sm">返  回</a>
                </div>
            </form>
        </div>
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    
    <script type="text/javascript">
	    function backToList() {
			var backUrl = "${backUrl}";
			if (backUrl != null && backUrl != "") {
				backUrl = unescape(backUrl);
				document.location = backUrl;
			} else {
				document.location = "${ctx }/auditUser/toAuditHospList.html";
			}
		}
    
    	//	保存用户信息
    	function auditSaveUser() {
    		if (!validate()) {
    			return;
    		}
    		$("#form").ajaxSubmit({
    			dataType : "json",
    			timeout: 10000,
    			success : function(result, statusText) {
    				if (result.success) {
    					var backUrl = "${backUrl}";
						document.location = "${ctx}/sysUser/printUserInfo.html?id=${user.id}&backUrl=" + backUrl;
    				} else {
    					$.HN.message.alert(result.msg || "", "消息", "error");
    				}
    			}
    		});
    	}
    	
    	//	校验用户信息
    	function validate() {
    		var name = $.trim($("#name").val());
    		if (name == null || name == "") {
    			$.HN.message.alert("请输入用户名称！", "消息", "warn");
    			return false;
    		}
    		
    		var email = $.trim($("#email").val());
    		if (email == null || email == "") {
    			$.HN.message.alert("请输入电子邮箱！", "消息", "warn");
    			return false;
    		} else if (!/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/.test(email)) {
    			$.HN.message.alert("电子邮箱格式不正确！", "消息", "warn");
    			return false;
    		}
    		
    		/* var locked = $.trim($("#locked").val());
    		if (locked == null || locked == "") {
    			$.HN.message.alert("请选择锁定状态！", "消息", "warn");
    			return false;
    		} */
    		
    		var roleId = $.trim($("#roleId").val());
    		if (roleId == null || roleId == "") {
    			$.HN.message.alert("请选择用户角色！", "消息", "warn");
    			return false;
    		}
    		
    		var phone = $.trim($("#phone").val());
    		if (phone == null || phone == "") {
    			$.HN.message.alert("请输入联系电话！", "消息", "warn");
    			return false;
    		}
    		
    		var status = $.trim($("#status").val());
    		if (status == null || status == "") {
    			$.HN.message.alert("请选择用户状态！", "消息", "warn");
    			return false;
    		}
    		
    		return true;
    	}
    
    	$(document).ready(function() {
    		
    	});
    </script>
    
</body>
</html>
